module ActsAsDebatable
  module Debate
    extend ActiveSupport::Concern
 
    included do
    end

    module ClassMethods
      def acts_as_debatable(options = {})
        has_many :comments, :as => :commentable, :dependent => :destroy
      end

      def acts_as_debater
	has_many :comments
      end

      def latest_debate
	Comment.where(:commentable_type => self.name).order("created_at desc").limit(10)
      end

      def count_comments
	Comment.where(:commentable_type => self.name).count
      end
    end

    def has_comments?
      if self.comments.count > 0
	true
      else
	false
      end
    end

    def latest_debate
      self.comments.order("created_at desc").limit(10)
    end

  end
end

ActiveRecord::Base.send :include, ActsAsDebatable::Debate
